from docx import Document

def process_table(table):
    text=""
    for row in table.rows:
        for cell in row.cells:
            if cell.tables:  # 检查当前单元格是否包含子表格
                for subtable in cell.tables:
                    text+=process_table(subtable)  # 递归处理子表格
            else:
                #处理当前单元格中的文本
                cell_text = " ".join([p.text for p in cell.paragraphs])
                text+=(cell_text+"\n")
    return text
                

def process_docx(file_data):
    doc = Document(file_data)
    text=""
    for table in doc.tables:
        text+=process_table(table)
    return text


"""# 使用示例
docx_file = "test-5.docx"
print(process_docx(docx_file))"""